package com.zksk.portal.controller.publicity;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksk.admin.api.RemoteDictService;
import com.zksk.admin.api.RemotePublicityService;
import com.zksk.admin.api.domain.SysDictData;
import com.zksk.admin.api.domain.portal.vo.SanctionsRequestVo;
import com.zksk.admin.api.domain.portal.vo.ViolateRequestVo;
import com.zksk.common.core.constant.PortalConstants;
import com.zksk.common.core.constant.SecurityConstants;
import com.zksk.common.core.domain.R;
import com.zksk.common.core.web.controller.BaseController;
import com.zksk.common.log.annotation.Log;
import com.zksk.common.log.enums.BusinessType;
import com.zksk.mbg.admin.domain.Sanctions;
import com.zksk.mbg.admin.domain.Violate;
import com.zksk.portal.domain.vo.LeftNavMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/publicity")
@Api(value = "PublicityController", tags = "门户信息公示相关接口")
public class PublicityController extends BaseController {

    @Autowired
    private RemoteDictService remoteDictService;

    @Autowired
    private RemotePublicityService remotePublicityService;

    /**
     * 政策资讯左侧菜单
     * @return
     */
    @GetMapping("/nav")
    @ApiOperation(value = "获取信息公示左侧菜单")
    public R<List<LeftNavMenuVo>> navMenu(){
        List<SysDictData> dictDataByCode = remoteDictService
                .getDictDataByCode(PortalConstants.PUBLICITY_DICT_CODE, SecurityConstants.INNER).getData();

        List<LeftNavMenuVo> resultList = dictDataByCode.stream().map(item -> {
            LeftNavMenuVo leftNavMenuVo = new LeftNavMenuVo();
            leftNavMenuVo.setValue(item.getDictValue());
            leftNavMenuVo.setLabel(item.getDictLabel());
            leftNavMenuVo.setType(item.getDictType());
            leftNavMenuVo.setDesc(item.getRemark());
            return leftNavMenuVo;
        }).collect(Collectors.toList());

        return R.ok(resultList,"菜单获取成功");
    }

    @Log(title = "违规通报查询",businessType = BusinessType.SELECT)
    @PostMapping("/violate")
    @ApiOperation(value = "违规通报查询")
    public R<Page<Violate>> violateList(@RequestBody ViolateRequestVo requestVo){
        //构建分页
        R<Page<Violate>> pageR = remotePublicityService.violatePage(requestVo, SecurityConstants.INNER);
        if (pageR.getCode() == R.SUCCESS) {
            Page<Violate> violatePage = pageR.getData();
            return R.ok(violatePage, "获取分页列表信息成功");
        }
        return R.fail("获取分页列表信息失败");
    }


    /**
     * 根据id查询信息
     * @param violateId
     * @return
     */
    @GetMapping(value = "/violate")
    @ApiOperation(value = "根据id查询信息")
    public R<Violate> selectViolate(@RequestParam("violateId") Long violateId) {
        R<Violate> violateR = remotePublicityService.selectViolate(violateId, SecurityConstants.INNER);
        if (violateR.getCode() == R.SUCCESS) {
            Violate violateById = violateR.getData();
            return R.ok(violateById, "查看详情信息成功");
        }
        return R.fail( "查看详情信息失败");
    }


    @Log(title = "奖惩信息列表查询",businessType = BusinessType.SELECT)
    @PostMapping("/sanctions")
    @ApiOperation(value = "奖惩信息列表查询")
    public R<Page<Sanctions>> sanctionsList(@RequestBody SanctionsRequestVo requestVo){
        //构建分页
        R<Page<Sanctions>> pageR = remotePublicityService.sanctionsPage(requestVo, SecurityConstants.INNER);
        if (pageR.getCode() == R.SUCCESS) {
            Page<Sanctions> violatePage = pageR.getData();
            return R.ok(violatePage, "获取分页列表信息成功");
        }
        return R.fail("获取分页列表信息失败");
    }

    /**
     * 根据id查询信息
     * @param sanctionsId
     * @return
     */
    @GetMapping(value = "/sanctions")
    @ApiOperation(value = "根据id查询信息")
    public R<Sanctions> selectSanctions(@RequestParam("sanctionsId") Long sanctionsId) {
        R<Sanctions> sanctionsR = remotePublicityService.selectSanctions(sanctionsId, SecurityConstants.INNER);
        if(sanctionsR.getCode() == R.SUCCESS) {
            Sanctions violateById = sanctionsR.getData();
            return R.ok(violateById, "查看详情信息成功");
        }
        return R.fail("查看详情信息失败");

    }

}
